<?php defined('SYSPATH') or die('No direct script access.');

class Controller_Pc_Api_V2_Tongyong extends Controller_Pc_Api_v2_Base
{
    // 数据请求结果
    private $result;

    /**
     * 参数验证对象
     * @var Request_Api_V2_Tongyong
     */
    private $validation;
    /**
     * 服务
     * @var Service_Api_Tongyong
     */
    private $service;

    public function before()
    {
        parent::before();
        $this->result = array(
            'status' => true,
            'msg' => '操作成功',
            'data' => array()
        );
        $this->validation = Request_Api_V2_Factory::create('tongyong', $this->request_params);
        $this->service = new Service_Api_Tongyong();
    }
    public function after()
    {
        $this->send_datagrams($this->client_info['id'], $this->result, $this->client_info['secret_key']);
    }

    //通用首页数据
    public function action_get_list()
    {
        try {
            $this->validation->get_list()->check();
            $data = $this->service->search($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }


    }


    //通用详细页
    public function action_get_detail()
    {
        try {
            $this->validation->get_detail()->check();
            $data = $this->service->info($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }



    //订单创建
    public function action_add_order()
    {
        try {
            $this->validation->add_order()->check();

            $this->request_params['member_info'] = $this->member_info;
            $data = $this->service->create_order($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }

    //当前套餐价格
    public function action_get_current_suit()
    {
        try {
            $this->validation->get_current_suit()->check();
            $data = $this->service->get_current_suit($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }
    //获得查询条件
    public function action_get_attr()
    {
        try {
            $this->validation->get_attr()->check();
            $data = $this->service->get_attr($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }




    /**
     * @function 获取通用产品日历报价
     */
    public function action_suit_calendar_price()
    {
        try {
            $this->validation->suit_calendar_price()->check();
            $data = $this->service->suit_calendar_price($this->request_params);
            $this->result['data'] = $data;
        } catch (Exception $e) {
            $this->result = array('status' => false, 'msg' => $e->getMessage());
        }

    }
}